<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="edu.fau.scanny.r.*"%>
<%@ page import="edu.fau.scanny.r.stromal.model.*"%>
<%@ page import="edu.fau.scanny.stromal.*"%>
<%@ page import="org.apache.commons.collections.map.MultiKeyMap"%>
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">

<title>Stromal Signal Calculator</title>
<link rel="stylesheet" href="css/table.css">
<!-- http://www.dzone.com/snippets/checkuncheck-all-checkboxes -->
<script  type="text/javascript">
	checked = false;

	function checkedAll() {
		if (checked == false) {
			checked = true
		} else {
			checked = false
		}

		for ( var i = 0; i < document.getElementById('rscript').elements.length; i++) {
			document.getElementById('rscript').elements[i].checked = checked;
		}
	}
</script>
</head>
<body>
	<table class="center">
		<tr>
			<td><a href="process.jsp"
				title="Click to see process description."><img
					src="img/selection_page_banner.png" height="400" width="1000"></a></td>
		</tr>
	</table>
	<h1 style="text-align: center">Stromal Signal Calculator</h1>
	<form method="post" action="rscript" name="rscript" target="_blank">
		&nbsp;&nbsp;&nbsp;<br>


		<table class="center">
			<thead>
				<tr>
					<td colspan=4>1. Choose normalization method: <br /> <small>*PLIER is preferred normalization
							method. MAS5 and RMA options are for comparison.</small></td>
				</tr>
			</thead>
			<tbody>
				<!--  compare plier and rma http://www.ncbi.nlm.nih.gov/pubmed?cmd=PureSearch&db=pubmed&term=10.1186%2F1471-2105-11-211%5Baid%5D -->
				<tr>
					<td><input name="normalization" value="plier16" type="radio"
						checked> <a
						href="http://media.affymetrix.com/support/technical/technotes/plier_technote.pdf"
						TITLE="Probe Logarithmic Intensity Error (PLIER) + 16. This option implements Affymetrix's PLIER algorithm and shifts the results up 16 units to improve log scale processing.">
							PLIER + 16</a><br />(Quantile Normalize)</td>
					<td><input name="normalization" value="plier" type="radio"> <a
						href="http://media.affymetrix.com/support/technical/technotes/plier_technote.pdf"
						TITLE="Probe Logarithmic Intensity Error (PLIER). This option implements Affymetrix's PLIER algorithm.">
							PLIER</a><br />(Quantile Normalize)</td>
					<td><input name="normalization" value="mas5" type="radio"><a
						href="http://media.affymetrix.com/support/technical/whitepapers/sadd_whitepaper.pdf"
						TITLE="This option computes Bioconductor's implementation of Affymetrix's MAS 5.0 expression measure as described in Statistical Algorithms Description Document by Affymetrix.">MAS5</a><br />(Quantile Normalize)</td>
					<td><input name="normalization" value="rma" type="radio">
						<a
						href="http://biostatistics.oxfordjournals.org/content/4/2/249.long"
						TITLE="This option computes the RMA (Robust Multichip Average) expression measure.">RMA
					</a><br />(Quantile Normalize)</td>
				</tr>
			</tbody>
		</table>

		<table class="center">
			<thead>
				<tr>
					<td colspan=7>2. Log2 or Linear Signal Output:<br /><small>*This
						selection does not affect any calculations. Output signal files
						will be returned in the chosen scale. This option is in
						consideration of the necessary scale of the signal values for any
						downstream analysis. For instance some network interference
						algorithms require signals to be in log2 scale.</small>
					</td>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td><input name="logLinear" value="linear" type="radio"
						checked>LINEAR</td>
					<td><input name="logLinear" value="log" type="radio">LOG2</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			</tbody>
		</table>
		<table class="center">
			<thead>
				<tr>
					<td>3. Choose data files (MUST select at least 1 Tissue AND 1 paired
						Lymphoid sample for each desired group):<br /> <big style="color: red;"><b>*Mouse
							over sample name to view QC values.</b></big>
					</td>
				</tr>
			</tbody>
		</table>
		<%
			String fName = this.getServletContext().getRealPath("CelFiles.txt");
			MultiKeyMap map = MetaFileUtils.createMetaFileMap(fName);
			Map<Integer, String> rowMap = MetaFileUtils.orderMap(this.getServletContext().getRealPath("Rows.txt"));
			Map<Integer, String> columnMap = MetaFileUtils.orderMap(this.getServletContext().getRealPath("Columns.txt"));
			Map<Integer, String> orderMap = MetaFileUtils.orderMap(this.getServletContext().getRealPath("Order.txt"));
		%>
		<table class="border">
			<tr>
				<td class="border" rowspan=2 style="text-align: center;">Time
					Point</td>
				<%
					for (int jj = 1; jj <= columnMap.size(); jj++) {
						String group = columnMap.get(jj);
				%>
				<td class="border" colspan=2 style="text-align: center;"><%=group%></td>
				<%
					}
				%>
			</tr>
			<tr>
				<%
					for (int jj = 1; jj <= columnMap.size(); jj++) {
						String group = columnMap.get(jj);
						for (int kk = 1; kk <= orderMap.size(); kk++) {
							String order = orderMap.get(kk);
				%>

				<td class="border" style="text-align: center;"><%=order%></td>
				<%
					}
					}
				%>
			</tr>

			<%
				for (int ii = 1; ii <= rowMap.size(); ii++) {
					String time = rowMap.get(ii);
			%>
			<tr>
				<td class="border" style="text-align: center;"><%=time%></td>
				<%
					for (int jj = 1; jj <= columnMap.size(); jj++) {
							String group = columnMap.get(jj);

							for (int kk = 1; kk <= orderMap.size(); kk++) {
								String order = orderMap.get(kk);
				%>
				<td class="border" valign=top><table>
						<%
							List<CelFile> celFiles = (List<CelFile>) map.get(time, group, order);
										for (CelFile celFile : celFiles) {
						%>
						<tr>
							<td style="text-align: left;"><input type="checkbox"
								name="chips" value="<%=celFile.getChipFile()%>" /> <a
								title="Percent Present = <%=celFile.getpPresent() + "\n"%>Scaling Factor = <%=celFile.getScalingFactor()%>"><%=celFile.getShortName()%></a>
							</td>
						</tr>

						<%
							}
						%>


					</table></td>

				<%
					}
						}
				%>

			</tr>
			<%
				}
			%>

		</table>
		<table class="centerCenter">
			<tr>
				<td class="centerCenter"><button value="submit" name="submit">
						<strong>Submit</strong>
					</button></td>
			</tr>
		</table>
	</form>
</body>
</html>